package com.ddzj.scaffold.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 密码处理
 * @Author:yangzibo
 * @CreateTime:2024-04-14 12:28
 * @Description:
 * @Version:1.0
 **/
@Component
public class DefaultPasswordEncoder extends BCryptPasswordEncoder {
    private Logger logger = LoggerFactory.getLogger(DefaultPasswordEncoder.class);

    @Override
    public String encode(CharSequence rawPassword) {
        return rawPassword.toString();
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        if (rawPassword == null) {
            throw new IllegalArgumentException("rawPassword cannot be null");
        }
        if (encodedPassword == null || encodedPassword.length() == 0) {
            logger.error("Empty encoded password");
            throw new IllegalArgumentException("encodedPassword is null");
        }
        return encodedPassword.equals(rawPassword);
    }
}
